package com.briup.day16;

/**
 * @author ThinkBook
 */
public class Test06_Inner {
    public static void main(String[] args) {
        //调用外部类的disp()方法
        Outer ot = new Outer();
        ot.disp();

        //创建内部类对象：依赖外部类对象
        Outer.Inner oi = new Outer().new Inner();
        Outer.Inner oi2 = ot.new Inner();
        oi.show();
        oi.equalsNameTest(30);
    }
}
//外部类
class Outer{
    private int o_num = 10;
    private static int s_num = 10;
    private int num = 10;

    //定义成员内部类
    class Inner{
        private  int i_num = 20;
        private  int num = 20;

        public void show(){
            System.out.println("in Inner disp()...");
            System.out.println("i_num" + i_num);
            System.out.println("o_num" + o_num);
            System.out.println("s_num" + s_num);
        }
        //同名变量如何区分
        //【局部、外部类成员、内部类成员】同名变量如何区分
        public void equalsNameTest(int num) {
            System.out.println("局部: " + num);
            System.out.println("内部类成员: " + this.num);
            //访问外部类中的数据成员：外部类名.this.成员名;
            System.out.println("外部类成员: " + Outer.this.num);
        }
    }

    //外部类 成员方法
    public void disp(){
        System.out.println("in Outer disp()...");
        System.out.println("o_num" + o_num);
        //外部类方法中直接访问 内部类私有成员: 必须依赖对象
        // 类类型 引用名 = new 类类型();
        Outer.Inner inn = new Outer.Inner();
        //在外部类中可以省略
        Inner inn2 = new Inner();
        System.out.println("inn.i_num: " + inn.i_num);
    }
}
